Skip to content

Add <auto-generated> header to output file - #66

Merged
christianhelle merged 9 commits into
mainfrom
generated-code-header
Jul 14, 2026
Merged

Add <auto-generated> header to output file#66
christianhelle merged 9 commits into
mainfrom
generated-code-header

Conversation

@christianhelle

@christianhelle christianhelle commented Jul 13, 2026

Copy link
Copy Markdown
Owner
  • Add generated header helper with deterministic render and unit tests
  • Wire generated header into CLI and library outputs
  • Regenerate sample outputs with generated header
  • Add lines to header

Summary by CodeRabbit

  • New Features

    • Generated code now includes an automatic header with the generator version and UTC generation timestamp.
    • Model-only output also includes the generated header and regeneration disclaimer.
  • Documentation

    • Updated the library API documentation and usage example to reflect the additional I/O parameter.
  • Tests

    • Added coverage for generated header content and model-only generation output.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@christianhelle, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 7 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4f0d87d4-5b4d-42a7-8cdb-310693ef59f7

📥 Commits

Reviewing files that changed from the base of the PR and between 0a36359 and dd23850.

📒 Files selected for processing (5)
  • README.md
  • src/generator.zig
  • src/generators/generated_header.zig
  • src/lib.zig
  • src/tests/generated_header_tests.zig
📝 Walkthrough

Walkthrough

generateCode now accepts an io handle and prepends a versioned UTC timestamp header to generated output. New header rendering functions, updated callers and documentation, and tests cover direct rendering and models-only generation.

Changes

Generated header integration

Layer / File(s) Summary
Header rendering primitives
src/generators/generated_header.zig
Adds functions that render generated-file comments using version and UTC timestamp values.
Code generation API and output
src/lib.zig, src/generator.zig, README.md, examples/example_usage.zig
Threads io through generateCode, prepends the rendered header to generated output, and updates documented and example call sites.
Header test registration and coverage
src/tests.zig, src/tests/generated_header_tests.zig
Registers tests for exact header rendering and header content in models-only output.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant generateCode
  participant generated_header
  participant GeneratorOutput
  Caller->>generateCode: pass allocator, io, document, args
  generateCode->>generated_header: renderNow version and timestamp
  generated_header-->>generateCode: generated header
  generateCode->>GeneratorOutput: write header and generated code
Loading

Possibly related PRs

Suggested labels: enhancement

Suggested reviewers: h0rv, keeshux, copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding an auto-generated header to generated output files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch generated-code-header

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/lib.zig (1)

227-230: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated version-string + header construction across src/lib.zig and src/generator.zig. Both call sites independently format the same "{s} ({s})" version string and call generated_header.renderNow with it; a small shared helper in generated_header.zig would remove the duplication and keep both call sites in sync if version_info or the header contract changes.

  • src/lib.zig#L227-L230: replace with a single call to a new helper, e.g. generated_header.renderNowFromBuildInfo(allocator, io, version_info).
  • src/generator.zig#L128-L131: replace with the same helper call.
♻️ Proposed shared helper
// src/generators/generated_header.zig
pub fn renderNowFromBuildInfo(allocator: std.mem.Allocator, io: std.Io, version_info: anytype) ![]const u8 {
    const version = try std.fmt.allocPrint(allocator, "{s} ({s})", .{ version_info.VERSION, version_info.GIT_COMMIT });
    defer allocator.free(version);
    return try renderNow(allocator, io, version);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib.zig` around lines 227 - 230, Extract the duplicated version
formatting and generated-header rendering into a shared renderNowFromBuildInfo
helper in src/generators/generated_header.zig, preserving the existing
allocator, io, version_info.VERSION, and version_info.GIT_COMMIT behavior.
Replace the separate construction in src/lib.zig lines 227-230 and
src/generator.zig lines 128-131 with calls to this helper, retaining appropriate
header ownership cleanup at each call site.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Line 375: Update the generated output documentation near generateCode to
mention the versioned <auto-generated> header and clarify that regenerated Zig
sources may differ even when the API surface is unchanged.

In `@src/lib.zig`:
- Around line 224-241: The models_code allocation in the generation flow has
overlapping cleanup paths. Replace the errdefer and branch-specific cleanup
around generateModels with one unconditional defer allocator.free(models_code),
and remove the manual allocator.free(models_code) inside the args.models_only
branch while preserving both return paths.

In `@src/tests/generated_header_tests.zig`:
- Around line 5-17: Update both tests in the generated header test file to
import and use test_utils.createTestAllocator() instead of
std.testing.allocator. Initialize the allocator wrapper, obtain its allocator
for generated_header.render, and add the required cleanup defer consistent with
the project’s test pattern.

---

Nitpick comments:
In `@src/lib.zig`:
- Around line 227-230: Extract the duplicated version formatting and
generated-header rendering into a shared renderNowFromBuildInfo helper in
src/generators/generated_header.zig, preserving the existing allocator, io,
version_info.VERSION, and version_info.GIT_COMMIT behavior. Replace the separate
construction in src/lib.zig lines 227-230 and src/generator.zig lines 128-131
with calls to this helper, retaining appropriate header ownership cleanup at
each call site.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ae88574f-2fb6-43af-8c27-9879b60df9f4

📥 Commits

Reviewing files that changed from the base of the PR and between 6dd514e and 0a36359.

⛔ Files ignored due to path filters (8)
  • generated/generated_v2.zig is excluded by !**/generated/**
  • generated/generated_v2_yaml.zig is excluded by !**/generated/**
  • generated/generated_v3.zig is excluded by !**/generated/**
  • generated/generated_v31.zig is excluded by !**/generated/**
  • generated/generated_v31_yaml.zig is excluded by !**/generated/**
  • generated/generated_v32.zig is excluded by !**/generated/**
  • generated/generated_v3_yaml.zig is excluded by !**/generated/**
  • generated/lmstudio.zig is excluded by !**/generated/**
📒 Files selected for processing (7)
  • README.md
  • examples/example_usage.zig
  • src/generator.zig
  • src/generators/generated_header.zig
  • src/lib.zig
  • src/tests.zig
  • src/tests/generated_header_tests.zig

Comment thread README.md Outdated
Comment thread src/lib.zig
Comment thread src/tests/generated_header_tests.zig
@christianhelle christianhelle self-assigned this Jul 14, 2026
@christianhelle christianhelle added the enhancement New feature or request label Jul 14, 2026
@christianhelle
christianhelle merged commit 0f91010 into main Jul 14, 2026
20 checks passed
@christianhelle
christianhelle deleted the generated-code-header branch July 14, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant